package logic

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/pkg/jwt"

	"gitee.com/Cauchy_AQ/vxopen/api/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RefreshTokenLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRefreshTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshTokenLogic {
	return &RefreshTokenLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RefreshTokenLogic) RefreshToken(req *types.RefreshReq) (resp *types.RefreshResp, err error) {
	aToken, rToken, err := jwt.RefreshToken(req.AccessToken, req.RefreshToken)
	if err != nil {
		return nil, err
	}
	return &types.RefreshResp{
		AccessToken:  aToken,
		RefreshToken: rToken,
	}, nil
}
